CONTENTS | INDEX | PREV | NEXT
strbpl
NAME
strbpl - unpack a string-array buffer into an array of pointers
SYNOPSIS
int num = strbpl(av, max, sary)
char **av;
int max;
const char *sary;
FUNCTION
Unpacks a string-array into an array of string pointers. The
string array is a series of nul terminated strings strung together
and terminated by a final nul. A pointer to each string is placed
in the arary-of-pointers (av) with a final NULL entry assuming
the number of strings does not exceed (max-1)
EXAMPLE
#include <stdio.h>
#include <string.h>
#include <assert.h>
main()
{
char *sary = "this0is0a0test00";
char *av[16];
int n;
#define arysize(x) (sizeof(x)/sizeof((x)[0]))
n = strbpl(av, arysize(av), sary);
assert(n == 4); /* n == 4 */
puts(av[0]); /* this */
puts(av[1]); /* is */
puts(av[2]); /* a */
puts(av[3]); /* test */
assert(av[4] == NULL); /* av[4] == NULL */
return(0);
}
INPUTS
char **av; pointer to a preallocated array of pointers
int max; the maximum number of entries in the above array
char *sary; pointer to a packed string.
RESULTS
int num; number of pointers loaded into the av array not
including the final NULL. If num == max then
the av array was not large enough to fit all
the strings or the final NULL.
SEE ALSO